﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Linq;
using System.Text;

namespace Ashlen.Portal.Core.DTO
{
    [DataContract(Namespace = "http://www.sukul.org/", Name = "User")]
    [Serializable]
    public class User
    {
        [DataMember(IsRequired = false, Name = "basicInfo")]
        public BasicInfo basicInfo = null;

        [DataMember(IsRequired = false, Name = "personalInfo")]
        public PersonalInfo personalInfo = null;
        
        [DataMember(IsRequired = false, Name = "mailSettings")]
        public MailSettings mailSettings = null;
    }

    [DataContract(Namespace = "http://www.sukul.org/", Name = "BasicInfo")]
    [Serializable]
    public class BasicInfo
    {
        [DataMember(IsRequired = false, Name = "Id")]
        public string Id = string.Empty;

        [DataMember(IsRequired = false, Name = "Username")]
        public string Username = string.Empty;

        [DataMember(IsRequired = false, Name = "Firstname")]
        public string Firstname = string.Empty;

        [DataMember(IsRequired = false, Name = "Lastname")]
        public string Lastname = string.Empty;

        [DataMember(IsRequired = false, Name = "Email")]
        public string Email = string.Empty;

        [DataMember(IsRequired = false, Name = "Password")]
        public string Password = string.Empty;
    }

    [DataContract(Namespace = "http://www.sukul.org/", Name = "PersonalInfo")]
    [Serializable]
    public class PersonalInfo
    {
        [DataMember(IsRequired = false, Name = "Nickname")]
        public string Nickname = string.Empty;

        [DataMember(IsRequired = false, Name = "DateOfBirth")]
        public string DateOfBirth = null;

        public DateTime? FormattedDateOfBirth
        {
            get
            {
                if (DateOfBirth != null && DateOfBirth.Trim() != string.Empty)
                {
                    try
                    {
                        return DateTime.Parse(DateOfBirth);
                    }
                    catch { }
                    return null;
                }
                return null;
            }
        }

        [DataMember(IsRequired = false, Name = "Sex")]
        public string Sex = string.Empty;

        [DataMember(IsRequired = false, Name = "Mobile")]
        public string Mobile = string.Empty;

        [DataMember(IsRequired = false, Name = "AvatarUrl")]
        public string AvatarUrl = string.Empty;

        [DataMember(IsRequired = false, Name = "Phone")]
        public string Phone = string.Empty;

        [DataMember(IsRequired = false, Name = "Postcode")]
        public string Postcode = string.Empty;

        public int? FormattedPostcode
        {
            get
            {

                if (Postcode != null && Postcode.Trim() != string.Empty)
                {
                    try
                    {
                        return int.Parse(Postcode);
                    }
                    catch { }
                    return null;
                }
                return null;
            }
        }

        [DataMember(IsRequired = false, Name = "State")]
        public string State = string.Empty;

        [DataMember(IsRequired = false, Name = "Country")]
        public string Country = string.Empty;

        [DataMember(IsRequired = false, Name = "Comment")]
        public string Comment = string.Empty;
    }

    [DataContract(Namespace = "http://www.sukul.org/", Name = "MailSettings")]
    [Serializable]
    public class MailSettings
    {
        [DataMember(IsRequired = false, Name = "AcceptAdvertisingEmail")]
        public bool AcceptAdvertisingEmail = false;

        [DataMember(IsRequired = false, Name = "AcceptCommunityEmail")]
        public bool AcceptCommunityEmail = false;
    }
}
